/**
 * This class handles the displaying of the video.
 */

package com.in2solar.in2solarmonitor.client;

import com.google.gwt.user.client.Window;

public class Video {
	
	// The loadVideo method decides what type of video to play, and then generates the embed code for it.
	public static void loadVideo(String vidType, String vidID){
		
		// The vidURL string is used to generate the complete video URL.
		String vidURL = new String();
		
		// If the video is a YouTube video...
		if (vidType == "youtube"){
			
			// Generate the video URL
			vidURL = "http://www.youtube.com/v/" + vidID;
			
			// Generate the embed code
			displayVideo("<object width=\"" + In2SolarMonitor.pageWidth +  "\" height=\"" + In2SolarMonitor.pageHeight + "\"><param name=\"movie\" value=\"" + vidURL + "&autoplay=1&color1=0xb1b1b1&color2=0xcfcfcf&hl=en_US&feature=player_embedded&fs=1\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowScriptAccess\" value=\"always\"></param><embed src=\"" + vidURL + "&autoplay=1&color1=0xb1b1b1&color2=0xcfcfcf&hl=en_US&feature=player_embedded&fs=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowScriptAccess=\"always\" width=\"" + In2SolarMonitor.pageWidth +  "\" height=\"" + In2SolarMonitor.pageHeight + "\"></embed></object>");
			
			// And start the timer for the duration of the video.
			StartTimer.t.schedule(In2SolarMonitor.vidDurationMill);
		}
		
		// And if it is a Vimeo video...
		else if (vidType == "vimeo"){
			
			// Generate the video URL
			vidURL = "http://www.vimeo.com/" + vidID;
			
			// Generate the embed code
			displayVideo("<object width=\"" + In2SolarMonitor.pageWidth +  "\" height=\"" + In2SolarMonitor.pageHeight + "\"><param name=\"allowfullscreen\" value=\"true\" /><param name=\"allowscriptaccess\" value=\"always\" /><param name=\"movie\" value=\"http://vimeo.com/moogaloop.swf?clip_id=" + vidID + "&amp;server=vimeo.com&amp;autoplay=1&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1\" /><embed src=\"http://vimeo.com/moogaloop.swf?clip_id=" + vidID + "&amp;server=vimeo.com&amp;show_title=0&amp;autoplay=1&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\" width=\"" + In2SolarMonitor.pageWidth +  "\" height=\"" + In2SolarMonitor.pageHeight + "\"></embed></object>");
			
			// And start the timer for the duration of the video
			StartTimer.t.schedule(In2SolarMonitor.vidDurationMill);
		}
		else {
			
			// If the video type was not supported, show an error...
			Window.alert("Video site is not supported. An error has occured.");
		}
	}
	
	// The displayVideo method sends the generated embed code to the HTML panel.
	public static void displayVideo(String URL){
		In2SolarMonitor.html.setHTML(URL);
	}
}
